#include "stdio.h"
#include "stdlib.h"

typedef int datatype;
typedef struct node
{
	datatype data;
	struct node *next;
} node;
typedef struct link
{
	struct node *front;
	struct node *rear;
} link;

link *creatlink()
{
	link *l = (link *)malloc(sizeof(link));
	l->front = (node *)malloc(sizeof(node));
	l->rear = l->front;
	l->front->next = NULL;
	return l;
}
void enterlink(link *l, datatype n)
{
	node *p = (node *)malloc(sizeof(node));
	p->data = n;
	p->next = NULL;
	l->rear->next = p;
	l->rear = p;
}
datatype outlink(link *l)
{
	int e;
	if (l->front == l->rear)
	{
		printf("ERROR");
		return NULL;
	}
	node *p = l->front;
	e = p->next->data;
	l->front = p->next;

	free(p);
	return e;
}
void printlink(link *l)
{
	node *p = l->front;
	while (p != l->rear)
	{

		p = p->next;
		printf("%  d  ", p->data);
	}
	printf("\n");
}
int empty(link *l)
{
	return l->rear == l->front ? 0 : 1;
}
void test1()
{
	link *l = creatlink();
	printf("\n%d\n", empty(l));

	enterlink(l, 1);
	enterlink(l, 2);
	printlink(l);
	printf("\n%d\n", empty(l));
	outlink(l);
	printlink(l);
	printf("\n%d\n", empty(l));
	outlink(l);
	outlink(l);
	printf("\n%d\n", empty(l));
}
